package com.nicefact.mailmonitor.workflow.service;
import net.sf.jsr107cache.Cache;
import net.sf.jsr107cache.CacheManager;

import org.springframework.stereotype.Service;

import com.google.appengine.api.taskqueue.Queue;
import com.google.appengine.api.taskqueue.QueueFactory;
import com.google.appengine.api.taskqueue.TaskOptions;
import com.nicefact.mailmonitor.workflow.WorkflowContext;

@Service
public class QueueService {

	
	public void triggerWorkflow(WorkflowContext context) {
		//System.out.println("workflow triggered : " + context.getWorkflowInfo().getWorkflowInstance());
		Queue queue = QueueFactory.getQueue("call-workflow");
		TaskOptions options = TaskOptions.Builder.withUrl("/resource/task/performworkflowtasks.do");
		CacheManager cmanager=CacheManager.getInstance();
		Cache cache=cmanager.getCache("WorkflowContextCache");
		cache.put(context.getWorkflowInfo().getWorkflowInstance(),context);
		options.param("workflowinstanceid", context.getWorkflowInfo().getWorkflowInstance());
		queue.add(options);
		}  

}

